package IO;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileCopyTools {
    public static void main(String[] args) {
        copyFile("d:/a.jpg","d:/new4.jpg");
    }
    public static void copyFile(String src, String des){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try{
            fis = new FileInputStream(src);
            fos = new FileOutputStream(des);
            bis = new BufferedInputStream(fis);
            bos = new BufferedOutputStream(fos);
            int temp = 0;
            while((temp = bis.read()) != -1){
                bos.write(temp);
            }
            bos.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(bis != null){
                    bis.close();
                }
                if(fis != null){
                    fis.close();
                }
                if(bos != null){
                    bos.close();
                }
                if(fos != null){
                    fos.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
